package br.com.californiahotel.client.viewControler;

import br.com.californiahotel.client.architecture.viewController.BasicView;
import br.com.californiahotel.client.viewControler.MainController.Display;

import com.smartgwt.client.types.ImageStyle;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VStack;

public class MainView extends BasicView implements Display{

	private Canvas mainContent;
	private ImgButton AptoButton;
	private HLayout hStack;
	private ImgButton serviceButton;
	private ImgButton hospedeButton;
	private ImgButton reservaButton;
	private ImgButton logoutButton;
	private ImgButton locationButton;

	public MainView() {
		mountView();
		setHeight100();
		setWidth100();
	}

	private void mountView() {
		Img img = new Img("topo.jpg");
		img.setHeight(130);

		hStack = new HLayout();
		hStack.setWidth100();

		VStack vStack = new VStack();
		vStack.setHeight100();

		SectionStack sectionStack = new SectionStack();
		sectionStack.setHeight100();
		sectionStack.setWidth(180);

		SectionStackSection servicosStackSection = mountServicoStackSection();
		SectionStackSection manutencaoStackSection = mountManutencaoStackSection();
		SectionStackSection systemStackSection = mountSystemStackSection();

		sectionStack.addSection(servicosStackSection);
		sectionStack.addSection(manutencaoStackSection);
		sectionStack.addSection(systemStackSection);

		vStack.addMember(sectionStack);
		hStack.addMember(vStack);

		addMember(img);
		addMember(hStack);
	}

	private SectionStackSection mountServicoStackSection() {
		SectionStackSection servicosStackSection = new SectionStackSection("Servi\u00E7os");
		servicosStackSection.setExpanded(false);

		reservaButton = new ImgButton();
		reservaButton.setSrc("reserva.png");
		reservaButton.setImageType(ImageStyle.CENTER);
		reservaButton.setHeight(25);
		
		locationButton = new ImgButton();
		locationButton.setSrc("key.png");
		locationButton.setImageType(ImageStyle.CENTER);
		locationButton.setHeight(25);

		servicosStackSection.addItem(reservaButton);
		servicosStackSection.addItem(locationButton);
		return servicosStackSection;
	}

	private SectionStackSection mountSystemStackSection() {
		SectionStackSection systemStackSection = new SectionStackSection("Sistema");
		systemStackSection.setExpanded(false);

		logoutButton = new ImgButton();
		logoutButton.setSrc("logout.png");
		logoutButton.setImageType(ImageStyle.CENTER);
		logoutButton.setHeight(25);

		systemStackSection.addItem(logoutButton);
		return systemStackSection;
	}

	private SectionStackSection mountManutencaoStackSection() {
		SectionStackSection manutencaoStackSection = new SectionStackSection("Manutencao");
		manutencaoStackSection.setExpanded(false);

		AptoButton = new ImgButton();
		AptoButton.setSrc("Apartamento.png");
		AptoButton.setImageType(ImageStyle.CENTER);
		AptoButton.setHeight(25);

		serviceButton = new ImgButton();
		serviceButton.setSrc("servico.png");
		serviceButton.setImageType(ImageStyle.CENTER);
		serviceButton.setHeight(25);

		hospedeButton = new ImgButton();
		hospedeButton.setSrc("baggage.jpg");
		hospedeButton.setImageType(ImageStyle.NORMAL);
		hospedeButton.setHeight(25);

		manutencaoStackSection.addItem(AptoButton);
		manutencaoStackSection.addItem(serviceButton);
		manutencaoStackSection.addItem(hospedeButton);
		return manutencaoStackSection;
	}

	public void changeContent(Canvas content){
		if(mainContent != null){
			mainContent.destroy();
		}
		mainContent = content;
		hStack.addMember(mainContent);
		mainContent.markForRedraw();
	}

	@Override
	public ImgButton getAptoButton() {
		return AptoButton;
	}

	@Override
	public ImgButton getServicesButton() {
		return serviceButton;
	}

	@Override
	public ImgButton getBaggageButton() {
		return hospedeButton;
	}

	@Override
	public ImgButton getLogoutButton() {
		return logoutButton;
	}

	@Override
	public ImgButton getReservaButton() {
		return reservaButton;
	}

	@Override
	public ImgButton getLocationButton() {
		return locationButton;
	}
}
